import {
  requestWithErrorHandling,
  streamRequestWithErrorHandling,
} from "./request";

// 发送聊天消息（非流式）
export function sendChatMessage(data, config = {}) {
  return requestWithErrorHandling({
    url: "/chat/send",
    method: "POST",
    data: {
      message: data.message,
      conversation_id: data.conversation_id,
      service: data.service || "gemini", // 默认使用 gemini 服务
    },
    timeout: config.timeout || 300000, // 5分钟超时
    errorMessage: config.errorMessage || "发送消息失败",
  });
}

// 发送聊天消息（流式响应）
export async function sendChatMessageStream(
  data,
  onMessage,
  onError,
  onComplete,
  config = {}
) {
  return streamRequestWithErrorHandling({
    url: "/chat/stream",
    method: "POST",
    data: {
      message: data.message,
      conversation_id: data.conversation_id,
      service: data.service || "gemini", // 默认使用 gemini 服务
    },
    onMessage,
    onError,
    onComplete,
    config,
    errorMessage: config.errorMessage || "发送聊天消息失败",
  });
}
